package com.travel.bhelp.common.config;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.nacos.api.exception.NacosException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class NacosConfig {

    @Bean
    public NacosDiscoveryProperties nacosDiscoveryProperties(
            NacosServiceManager nacosServiceManager) throws NacosException {
        NacosDiscoveryProperties properties = new NacosDiscoveryProperties();
        properties.setServerAddr("http://127.0.0.1:8848");
        properties.setUsername("nacos");
        properties.setPassword("nacos123");
        properties.setNamespace("public");
        properties.setService("bhelp-service");
        properties.setGroup("DEFAULT_GROUP");

        // 测试Nacos连接
        nacosServiceManager.getNamingService().getServerStatus();
        log.info("Nacos连接成功");

        return properties;
    }
}
